package com.fzt.framework.user;

import org.springframework.security.core.context.SecurityContextHolder;

/**
 * <p>
 *
 * </p>
 *
 * @author 非洲铜
 * @since 2022-12-11
 */
public class SecurityUser {

    /**
     * 获取用户信息
     */
    public static UserDetail getUser() {
        UserDetail user;
        try {
            user = (UserDetail) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        } catch (Exception e) {
            return new UserDetail();
        }
        return user;
    }

    /**
     * 获取用户ID
     */
    public static Long getUserId() {
        return getUser().getId();
    }
}
